<template>
    <div class="bindWX">
         <div v-if="isShow" class="wxCode" @keyup.tab="cancle">
             <iframe :src="wechatPicUrl" height="400" style="width:100%; border:none;"></iframe>
            <!-- <p>请使用微信二维码扫描绑定</p> -->
            <el-button style="opacity: 0;" @keyup.tab="cancle"></el-button>
         </div>
         <div v-else class="wxName">
             <p>当前已绑定微信：{{wxName}}</p>
             <el-button type="success" @click="cancleBind">取消绑定</el-button>
         </div>
    </div>
</template>

<script>
import {getWeChatBinding,updateWeChatBinding} from '@/api/common/auth/userInfo/index.js'
export default {
    name:"bindWX",
    data () {
        return {
            wxName:"",
            isShow:true,
            userNum:"123456",
            wechatPicUrl:"",
        }
    },
    mounted () {
        getWeChatBinding().then(res=>{
            // console.log(res,"456")
            // if(res.resultCode == 200){
                console.log(res.data,"res.data.data1")
                if(res.type == 1){
                    // console.log(res.data,"res.data.data")
                    this.wechatPicUrl = res.data
                }else if(res.type == 2){
                    // console.log(res.data,"isShow")
                    this.isShow=false
                    this.wxName = res.data
                }
            // }
        })  
    },
    methods: {
        cancleBind(){
            console.log('取消绑定')
            let params={
                    type:3,
                }
            updateWeChatBinding(params).then(res=>{
                console.log(res,"res")
                this.$router.go(0)
                if(res.resultCode == 200){
                    // this.$router.push('/admin/auth/userInfo')
                }
                
            })
            
        },
        //当前微信已绑定是否继续绑定
        /* open2() {
            this.$confirm(``, '提示', {
            confirmButtonText: '继续绑定',
            cancelButtonText: '取消',
            dangerouslyUseHTMLString: true,
            message: `<p>当前微信已绑定员工编号：<i>${this.userNum}</i></p><p>如继续绑定，则将于原账号进行解绑</p>`,
            type: 'warning'
            }).then(() => {
                this.isBindPhone=false
                let postBindingPhoneData={
                    phone:this.loginPhoneForm.getPhone,
                    appId:this.loginForm.appId,
                    username:this.loginForm.username,
                    confirm:1,
                    }
                postBindingPhone(postBindingPhoneData).then(res=>{
                console.log(res,"是否继续绑定")
                })
           
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消'
            });          
            });
        }, */
        cancle(){
            this.isShow=false
        }
    },
}
</script>

<style lang="less" scoped>
.bindWX {
    .wxCode{
        text-align: center;
    }
    .wxName{
        text-align: center;
        p{
           line-height: 50px;
        }
    }
}
</style>
